# -*- coding: utf-8 -*-
# @Software :   PyCharm
# @File     :   adminx.py
# @Author   :   zhaolie
# @Contact  :   zhaolie1989@gmail.com
# @Time     :   2019/11/16 10:48 下午
# @Desc     :   None      

# here put the import lib
import xadmin

from .models import UserAsk, UserFavorite, UserMessage, UserCourse, CourseComments


class UserAskAdmin:
    list_display = ["name", "mobile", "course_name", "add_time"]
    search_fields = ["name", "mobile", "course_name"]
    list_filter = ["name", "mobile", "course_name", "add_time"]


class UserFavoriteAdmin:
    list_display = ["user", "fav_id", "fav_type", "add_time"]
    search_fields = ["user__username", "fav_id", "fav_type"]
    list_filter = ["user__username", "fav_id", "fav_type", "add_time"]

    def has_delete_permission(self,obj=None):
        return True


class UserMessageAdmin:
    list_display = ["user", "message", "has_read", "add_time"]
    search_fields = ["user", "message", "has_read"]
    list_filter = ["user", "message", "has_read", "add_time"]

    def has_delete_permission(self,obj=None):
        return True


class UserCourseAdmin:
    list_display = ["user", "course", "add_time"]
    search_fields = ["user__username", "course"]
    list_filter = ["user__username", "course", "add_time"]

    def has_delete_permission(self,obj=None):
        return True


class CourseCommentsAdmin:
    list_display = ["user", "course", "comments", "add_time"]
    search_fields = ["user__username", "course__name", "comments"]
    list_filter = ["user__username", "course__name", "comments", "add_time"]

    def has_delete_permission(self,obj=None):
        return True


xadmin.site.register(UserAsk, UserAskAdmin)
xadmin.site.register(UserFavorite, UserFavoriteAdmin)
xadmin.site.register(UserMessage, UserMessageAdmin)
xadmin.site.register(UserCourse, UserCourseAdmin)
xadmin.site.register(CourseComments, CourseCommentsAdmin)
